package aufgabe3_chat.chatGui;

import java.awt.Font;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import aufgabe3_chat.Client_TCP;

public class Menue extends JFrame {

	private static final long serialVersionUID = 1L;
	private Menue menue;
	private Client_TCP client_tcp;
	private JPanel contentPane;
	private JTextField textField;
	private final Action starten = new SwingAction_1();
	private JTextField textField_1;
//	private JOptionPane error;

	/**
	 * Create the frame.
	 * @param client_tcp 
	 */
	public Menue(Client_TCP client_tcp) {
		this.menue = this;
		this.client_tcp = client_tcp;
	
		setTitle("Anmeldefenster");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 266, 184);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		
		JButton btnNewButton_1 = new JButton("Starten");
		btnNewButton_1.setAction(starten);
		btnNewButton_1.setBounds(10, 112, 89, 23);
		contentPane.add(btnNewButton_1);
		
		textField = new JTextField();
		textField.setBounds(10, 37, 233, 23);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(10, 80, 233, 23);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Serveradresse:");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNewLabel.setBounds(10, 11, 233, 23);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Anmeldename:");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNewLabel_1.setBounds(10, 58, 233, 21);
		contentPane.add(lblNewLabel_1);
	}

	private class SwingAction_1 extends AbstractAction {
	
		private static final long serialVersionUID = 1L;
		public SwingAction_1() {
			putValue(NAME, "Starten");
			putValue(SHORT_DESCRIPTION, "Startet den Client und meldet ihn an.");
		}
		public void actionPerformed(ActionEvent e) {
			client_tcp.set_server_ip(textField.getText());
			client_tcp.set_user_name(textField_1.getText());
			client_tcp.start();
			menue.dispose();
		}
	}
}
